package com.lhz.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.lhz.services.ChushiService;

@Controller
@RequestMapping("/chushi")//后厨管理
public class ChushiControll {
	/**
	 *                 _ooOoo_
	 *                o8888888o
	 *                88" . "88
	 *                (| -_- |)
	 *                O\  =  /O
	 *             ____/`---'\____
	 *           .'  \\|     |//  `.
	 *          /  \\|||  :  |||//  \
	 *         /  _||||| -:- |||||-  \
	 *         |   | \\\  -  /// |   |
	 *         | \_|  ''\---/''  |   |
	 *         \  .-\__  `-`  ___/-. /
	 *       ___`. .'  /--.--\  `. . __
	 *    ."" '<  `.___\_<|>_/___.'  >'"".
	 *   | | :  `- \`.;`\ _ /`;.`/ - ` : | |
	 *   \  \ `-.   \_ __\ /__ _/   .-` /  /
	 *====`-.____`-.___\_____/___.-`____.-'======
	 *                 `=---='
	 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	 *             佛祖保佑       永无BUG
	 */
	
	@Autowired
	private ChushiService service;	
	
	
	
	
	//restful
	/**
	 * 显示后厨列表信息 加上分页条件
	 * @return
	 */
	@RequestMapping(value="/chushishow")
	@ExceptionHandler
	public ModelAndView chushishow(
			@RequestParam(name="pageNow",required=false,defaultValue="1")int pageNow,
			@RequestParam(name="pageSize",required=false,defaultValue="5")int pageSize) {
		try {
			ModelAndView mv=new ModelAndView();
			Map<String, Object> info = service.searchBychushi(pageNow,pageSize);
			mv.addObject("map", info);
			mv.setViewName("Chushi");
			return mv;
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("查不出来后厨管理的信息出错啦！...在63");
	}
	
	
	/**
	 * 修改菜单状态改变
	 * @param dingdanId
	 * @param goodsId
	 * @param status
	 * @return
	 */
	@RequestMapping(value="/updatechushistatus",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> updatechushistatus(
			Integer dingdanId,
			Integer status){
		try {
			return service.updatechushistatus(dingdanId, status);
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("修改菜单状态出错啦!....在82行");
	}
	
	/**
	 * 取消订单和交易完成
	 * @param dingdan
	 * @param status
	 * @return
	 */
	@RequestMapping(value="/canceldingdan")
	@ResponseBody
	public Map<String,Object> updatecanceldingdan(
			String dingdan,
			Integer status){
		try {
			if(status!=null) {
				return service.updatecanceldingdan(dingdan, status);//一个是取消订单
			}else {
				return service.updatecanceldingdan(dingdan);//交易完成
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		throw new RuntimeException("取消订单和交易完成出错啦!.....在110行");
	}
	
	
	
	
	
}
